fix(code-example): handle quote variants and dedupe injected props#938
Open
Utkarsh-Singhal-26 wants to merge 2 commits intoDavidHDev:mainfrom
Open
fix(code-example): handle quote variants and dedupe injected props#938Utkarsh-Singhal-26 wants to merge 2 commits intoDavidHDev:mainfrom
Utkarsh-Singhal-26 wants to merge 2 commits intoDavidHDev:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the code-snippet prop injection logic used by CodeExample so usage strings are updated correctly when props use different quoting styles, and attempts to prevent duplicate injected props from appearing in rendered examples.
Changes:
- Expands the “simple prop” matching regex to recognize single-quoted and additional value forms.
- Replaces duplicate matches by keeping only the first occurrence and deleting subsequent occurrences.
- Adds a newline-collapsing pass after deduplication.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a code-example rendering issue (#937) where the same prop could appear twice in the Usage snippet when quote styles differed.
Problem
Some usage snippets had an existing prop written with single quotes, while dynamic prop updates are generated with double quotes.
Because the matcher did not fully account for both styles, it could fail to detect the existing prop and append a new one, causing duplicates.
Root Cause
The simple prop matcher handled only a subset of value formats and could miss valid single-quoted prop lines.
When matching failed, fallback logic appended a new prop instead of replacing the existing one.
Fix
Why This Works
The injector now recognizes equivalent prop lines regardless of quote style and replaces them in place.
If duplicates already exist, deduplication removes extras, preventing repeated props in generated Usage output.
Scope
This change only affects code-example generation.
There is no runtime behavior change to component logic.
Validation